﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ExceptionHandle
{
    public class ErrorModel
    {

        public ErrorModel()
        {

        }

        public ErrorModel(Exception exception)
        {
            this.EM(exception, MsgStatus.信息提示);
        }

        public ErrorModel(Exception exception, MsgStatus msgStatus)
        {
            this.EM(exception, msgStatus);
        }

        private void EM(Exception exception, MsgStatus msgStatus)
        {
            this.EM_Msg = exception.Message;
            this.status = (int)msgStatus;
            this.EM_Data = exception.Data;
            this.EM_Source = exception.Source;
            this.EM_StackTrace = exception.StackTrace;
            this.EM_TargetSite = exception.TargetSite != null ? exception.TargetSite.Name : null;

        }

        /// <summary>
        /// 错误消息
        /// </summary>
        public string EM_Msg { set; get; }

        /// <summary>
        /// 错误状态码
        /// </summary>
        public int status { set; get; }

        /// <summary>
        /// 异常信息键值对集合
        /// </summary>
        public object EM_Data { set; get; }

        /// <summary>
        /// 异常对象名或应用程序
        /// </summary>
        public string EM_Source { set; get; }

        /// <summary>
        /// 堆栈形式
        /// </summary>
        public string EM_StackTrace { set; get; }

        /// <summary>
        /// 当前引发异常的方法
        /// </summary>
        public string EM_TargetSite { set; get; }

    }

    /// <summary>
    /// 消息状态
    /// </summary>
    public enum MsgStatus
    {
        信息提示 = 10,
        登录超时 = 20,
        手动处理 = 30,
        程序异常 = 50
    }


}
